package com.yuke.cloud.service.opc.config;

import com.yuke.cloud.common.core.interceptor.PermitAuthenticationFilter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationProcessingFilter;
import org.springframework.security.web.DefaultSecurityFilterChain;
import org.springframework.stereotype.Component;

/*
 * <p>Company: Copyright (c) 2018. yuke All Rights Reserved. </br> </p>
 * <p>Title：yukemall </br> </p>
 * <p>com.yuke.cloud.service.opc.config Description TODO </br> </p>
 * @Author wg
 * @Date   2018/12/17 14:39
 */
@Component("permitAllSecurityConfig")
public class PermitAllSecurityConfig extends SecurityConfigurerAdapter<DefaultSecurityFilterChain,HttpSecurity> {

    @Value("${spring.profiles.active}")
    private String env;//当前激活的配置文件

    @Override
    public void configure(HttpSecurity http) throws Exception {
        // 开发环境下，不验证，对permetAll()的请求去掉token头，防止后续token验证
        if ("dev".equals(env)) {
            http.addFilterBefore(new PermitAuthenticationFilter(), OAuth2AuthenticationProcessingFilter.class);
        }
    }
}
